package com.awspaas.user.apps.shhtaerospaceindustrial.event_zhpj;

import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListenerInterface;
import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class UpdateSastUnitZhpjTestRecord extends ExecuteListener implements ExecuteListenerInterface {

	@Override
	public String getDescription() {
		return "更新综合评价,老总院部各部门评价记录信息.";
	}

	@Override
	public void execute(ProcessExecutionContext pec) throws Exception {
		try {
			String bindId = pec.getProcessInstance().getId();// 流程实例ID
			String queryResourceTaskFpId = "SELECT ID,APPLYUNIT,AUDITTYPE,APPLYUSERNAME,APPLYUSERZH,SOURCEPORJECTID FROM BO_EU_ZHPJ_PSN_AUDIT_HAED WHERE BINDID"
					+ " = '" + bindId + "'";

			List<Map<String, Object>> resourceTaskFpIdList = DBSql.query(queryResourceTaskFpId,
					new ColumnMapRowMapper());
			if (resourceTaskFpIdList != null && !resourceTaskFpIdList.isEmpty()) {
				for (int i = 0; i < resourceTaskFpIdList.size(); i++) {
					Map<String, Object> resourceTaskFpIdMap = resourceTaskFpIdList.get(i);
					String APPLYUNIT = objToStr(resourceTaskFpIdMap.get("APPLYUNIT"));
					String AUDITTYPE = objToStr(resourceTaskFpIdMap.get("AUDITTYPE"));
					String APPLYUSERNAME = objToStr(resourceTaskFpIdMap.get("APPLYUSERNAME"));
					String SOURCEPORJECTID = objToStr(resourceTaskFpIdMap.get("SOURCEPORJECTID"));

					String ID = objToStr(resourceTaskFpIdMap.get("ID"));

					if (SOURCEPORJECTID != null && (!("").equals(SOURCEPORJECTID))) {
						if (SDK.getTaskAPI().isChoiceActionMenu(pec.getTaskInstance(), "完成")) {
							if (AUDITTYPE != null && (("院部各部门").equals(AUDITTYPE))) {
								String updatesql = "UPDATE BO_EU_ZHPJ_YBMANAGE_PSNMX SET YBDEPTAUDITSTATUS = '已完成'  WHERE  YBDEPTAUDITPROSID = '"
										+ bindId + "' and APPLYUSERNAME='" + APPLYUSERNAME + "'";
								int updateflag = DBSql.update((updatesql));

								System.out.println("更新操作的结果是：" + updateflag);
							}
							if (AUDITTYPE != null && (("八院各单位").equals(AUDITTYPE))) {
								String updatesql = "UPDATE BO_EU_ZHPJ_YBMANAGE_PSNMX_CS SET GEUNITAUDITSTATUS = '已完成'  WHERE  GEUNITAUDITPROSID = '"
										+ bindId + "' and APPLYUSERNAME='" + APPLYUSERNAME + "'";
								int updateflag = DBSql.update((updatesql));

								System.out.println("更新操作的结果是：" + updateflag);
							}
						}
					}
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String objToStr(Object obj) {
		return obj == null ? "" : obj.toString();
	}

}
